package org.jeecg.modules.mapper;

import java.util.List;


import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.entity.DiyProfessorInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Component;

/**
 * @Description: 专家信息录入
 * @Author: Zhang Haoyu
 * @Date:   2020-05-21
 * @Version: V1.0
 */
@Component
public interface DiyProfessorInfoMapper extends BaseMapper<DiyProfessorInfo> {

    /**
     * 获得字典数据名字
     * @param id
     * @author Zhang Haoyu
     * @return
     */
    String selDictNameById(@Param("id") String id);

    /**
     * 根据id获取用户userid
     * @param id
     * @return
     */
    @Select("select ding_user_id from diy_professor_info where id = #{id}")
    String getDingDinguserid(String id);

    /**
     * 根据userid删除专家
     */
    @Delete("delete from diy_professor_info where ding_user_id = #{ding_user_id}")
    void deleteDingDinguserid(String ding_user_id);
    /**
     * 根据学校id获取数据名字
     * @param id
     * @author Zhang Haoyu
     * @return
     */

    @Select("select name from school where id = #{id}")
    String selSchoolById(@Param("id") String id);

    /**
     * 根据id查找专业名称
     * @param id
     * @author Zhang Haoyu
     * @return
     */
    @Select("select name from major where id = #{id}")
    String selMajorNameById(@Param("id") String id);

    /**
     * 根据id查找专家电话
     * @param id
     * @author Zhang Haoyu
     * @return
     */
    @Select("select professor_phone from diy_professor_info where id = #{id}")
    String selPhone(@Param("id") String id);

    /**
     * 根据钉钉userid更新用户请假状态
     * @param userid
     * @param fieldName
     * @param fieldValue
     * @return
     */
    @Update("update diy_professor_info set ${fieldName}=#{fieldValue} where ding_user_id = #{userid}")
    int updateDiyProfessorOneField(@Param("userid") String userid, @Param("fieldName") String fieldName,@Param("fieldValue")int fieldValue);


    /**
     * 根据钉钉userid更新用户请假状态
     * @param userid
     * @param fieldName
     * @param fieldValue
     * @return int
     */
    @Update("update diy_professor_info set ${fieldName}=#{fieldValue} where ding_user_id = #{userid}")
    int updateDiyProfessorOneField(@Param("userid") String userid, @Param("fieldName") String fieldName,@Param("fieldValue")String fieldValue);

    /**
     * 根据unionid获取id
     * @param unionid
     * @return String
     */
    @Select("select id from sys_user where username = #{username}")
    String getIdByUnionId(@Param("username") String unionid);


    /**
     * 根据unionid删除user表的信息
     * @param unionId
     * @return
     */
    @Delete("delete from sys_user where username=#{username}")
    Integer deleteProfessorByUnionId(@Param("username") String unionId);

    /**
     * 根据userId从数据库中获取UnionId
     * @param originator_userid
     * @return
     */
    @Select("select ding_unionid from diy_ding_user where ding_user_id=#{userId}")
    String getUnionIdByUserId(@Param("userId") String originator_userid);

    /**
     * 根据数据字典名称获取id
     * @param name 名称
     * @return id
     */
    @Select("select id from sys_category where name = #{name}")
    String selDictIdByName(@Param("name") String name);

    /**
     * 根据专业名称查找专业id
     * @param name
     * @return String
     */
    @Select("select id from major where name = #{name}")
    String selectMajorIdByName(@Param("name") String name);

    /**
     * 用户重新加入组织时候判断是否存在之前的信息，存在就更新userId
     * @param userId
     * @param oldUserId
     */
    @Update("update diy_professor_info set ding_user_id = #{newUserId} where ding_user_id = #{oldUserId}")
    void updateProfessorInfoByUserId(@Param("newUserId") String userId, @Param("oldUserId") String oldUserId);

    /**
     * 根据dingUserId查找专家信息，，避免逻辑删除
     * @param dingUserId
     * @return
     */
    @Select("select * from diy_professor_info where ding_user_id = #{dingUserId}")
    DiyProfessorInfo selectInfoByDIngUserId(@Param("dingUserId") String dingUserId);

    /**
     * 修改专家状态为可修改
     */
    @Update("update diy_professor_info set is_change_info = 1 where ding_user_id = #{originator_userid}")
    void upichangeinfo(@Param("originator_userid")String originator_userid);

    /**
     * 自定义分页查询
     * @return
     * @param diyProfessorInfo
     */
    List<DiyProfessorInfo> pageByEntity(@Param("diyProfessorInfo") DiyProfessorInfo diyProfessorInfo);

    /**
     *  更改专家在职离职状态
     * @param delFlag 删除状态
     */
    @Update("update diy_professor_info set del_flag = #{delFlag} where ding_user_id = #{userid}")
    void updateDiyProfessorDelFlag(@Param("delFlag") int delFlag,@Param("userid") String userid);

}
